package com.dlwx.firefighting.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.dlwx.firefighting.R;
import com.dlwx.firefighting.bean.GoodsBean;
import com.dlwx.firefighting.utils.LogUtils;
import com.dlwx.firefighting.utils.ScreenUtils;
import java.util.List;

/**
 * Created by Administrator on 2018/3/17.
 */

public class RecommentHorizonAdapter extends RecyclerView.Adapter<RecommentHorizonAdapter.GridViewHolder> {

    private final int width;
    private Context context;
    private List<GoodsBean> datas;
    public RecommentHorizonAdapter(Context context, List<GoodsBean> datas) {
        this.context=context;
        this.datas=datas;
        width=ScreenUtils.getScreenWidth(context);
    }
    public List<GoodsBean> getDatas(){
        return datas;
    }
    public void addAll(List<GoodsBean>  list) {
        int lastIndex = this.datas.size();
        if (this.datas.addAll(list)) {
            notifyItemRangeInserted(lastIndex, list.size());
        }
//        notifyDataSetChanged();
    }

    @Override
    public GridViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_product,parent,false);
        view.getLayoutParams().width=width/3;
        GridViewHolder viewHolder=new GridViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(GridViewHolder holder, int position) {
        GoodsBean bean = datas.get(position);
        LogUtils.i("-->"+bean.getProductName());
        holder.tv_name.setText("0000");
//        holder.tv_name.setText(bean.getProductName());
        holder.tv_price.setText(context.getString(R.string.rmb)+bean.getSalePrice());
        holder.tv_sale.setText("已售"+bean.getSaleNum()+"件");
        Glide.with(context).load(bean.getProductImageBig()).into(holder.img_product);
    }
    @Override
    public int getItemCount() {
        return datas.size();
    }

    public static  class GridViewHolder extends RecyclerView.ViewHolder{
        private ImageView img_product;
        private TextView tv_name,tv_sale,tv_price;
        public GridViewHolder(View itemView) {
            super(itemView);
            img_product= (ImageView) itemView.findViewById(R.id.img_product);
            tv_name= (TextView) itemView.findViewById(R.id.tv_name);
            tv_price= (TextView) itemView.findViewById(R.id.tv_price);
            tv_sale= (TextView) itemView.findViewById(R.id.tv_sale);
            tv_name= (TextView) itemView.findViewById(R.id.tv_name);
        }
    }
}
